package com.fusuhai.controller;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fusuhai.bean.UserBean;
import com.fusuhai.service.UserService;
import com.fusuhai.util.JWTUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("users")
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("login")
    public UserBean login(HttpServletRequest request, String userName, String userPwd, HttpServletResponse response) {
        UserBean userBean = userService.login(userName, userPwd);
        return userBean;
    }


    @RequestMapping("selectLevel")
    public PageInfo<UserBean> selectLevel(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                          @RequestParam(value = "pageSize", defaultValue = "5") int pageSize,
                                          String level) {
        return userService.selectLevel(pageNO, pageSize, level);
    }

    @RequestMapping("addUser")
    public void addUser(UserBean user) {
        userService.addUser(user);
    }

    @RequestMapping("update")
    public void update(int userId, String userPwd) {
        userService.updateUser(userId, userPwd);
    }

    @RequestMapping("delete")
    public void delete(int userId) {
        userService.deleteUser(userId);
    }

    @RequestMapping("date")
    public void date(String userAccount, LocalDate date) {
        userService.addDate(userAccount, date);
    }

    @RequestMapping("selectDateByDate")
    public PageInfo<UserBean> selectDateByDate(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                               @RequestParam(value = "pageSize", defaultValue = "5") int pageSize,
                                               LocalDate sDate,
                                               LocalDate eDate) {

        return userService.selectDate(pageNO, pageSize, sDate, eDate);
    }

    @RequestMapping("selectAllDate")
    public PageInfo<UserBean> selectAllDate(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                               @RequestParam(value = "pageSize", defaultValue = "5") int pageSize) {

        return userService.selectAllDate(pageNO, pageSize);
    }

}
